<include file="public@header"/>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="layui-input" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">{:lang('REPLACE')}</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">{:lang('REMOVE')}</a>
    </li>
</script>
</head>
<body>
    <div class="layui-fluid">
        <form action="{:url('AdminImg/editPost')}" method="post" class="layui-form js-ajax-form">
            <div class="layui-card">
                <div class="layui-card-header">编辑图片</div>
                <div class="layui-card-body">
                    
                    <!-- 文章标题 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('UPLOAD_IMAGE')}
                                        <br><span>(图片尺寸：1080*355)</span></label>
                                
                                    <div class="layui-input-block">
                                        <div class="upload-image">
                                            <input type="hidden" name="post[img]" id="thumbnail"
                                                   value="{$result.img|default=''}">
                                            <a href="javascript:uploadOneImage('{:lang('UPLOAD_IMAGE')}','#thumbnail');">
                                                <if condition="empty($result.img)">
                                                    <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                         id="thumbnail-preview"
                                                         width="150"/>
                                                    <else/>
                                                    <img src="{:cmf_get_image_preview_url($result.img)}"
                                                         id="thumbnail-preview"
                                                         width="150"/>
                                                </if>
                                            </a>
                                            <input type="button" class="layui-btn layui-btn-danger layui-btn-sm btn-cancel-thumbnail" value="{:lang('CANCEL_PICTURE')}">
                                        </div>
                                    </div>
                                </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="post[id]" value="{$result['id']}">
                            <input type="hidden" name="post[name]" value="{$result['name']}">
                            <if condition="cmf_auth_check(cmf_get_current_admin_id(), 'portal/AdminQuest/editPost')">
                                <button type="submit" class="layui-btn layui-btn-normal js-ajax-submit">{:lang('SAVE')}</button>
                            </if>
                            <a class="layui-btn layui-btn-primary" href="{:url('AdminImg/index')}">{:lang('BACK')}</a>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>

<include file="public@footer"/>
<include file="admin@theme/scripts"/>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
    $(function () {
        if( $('#detail_content').length ){
            // $('.content-preview').show();
            UE.getEditor('detail_content');
        }
        if( $('#post_excerpt').length ){
            UE.getEditor('post_excerpt');
        }
        //移除缩略图
        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });

    // 选择分类
    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?operate=add&ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
